home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / ar / files.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  107 lines

  1. /* $VER: ar files.c V0.1 (31.01.98)
  2.  *
  3.  * This file is part of ar, a portable archive maintanance
  4.  * utility for normal and BSD-style archives.
  5.  * Copyright (c) 1999  Frank Wille
  6.  *
  7.  * ar is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * ar may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.1  (31.01.99) phx
  17.  *       First working version, which only supports 'q' (quick append)
  18.  *       and 't' (table of contents), reads and writes normals and
  19.  *       BSD-style archives. Symbol table will not be created!
  20.  * v0.0  (30.01.99) phx
  21.  *       File created.
  22.  */
  23.  
  24. #ifdef AMIGA
  25. #include <dos/dos.h>
  26. #include <proto/dos.h>
  27. #define UNIXOFFSET 252457200  /* seconds from 1.1.70 to 1.1.78 */
  28.  
  29. #else /* UNIX */
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32.  
  33. #endif
  34. #include <string.h>
  35. #include "ar.h"
  36. #include "archive.h"
  37.  
  38.  
  39.  
  40. #ifdef AMIGA
  41.  
  42. void getfstat(struct ArObject *obj,char *name)
  43. /* Amiga version */
  44. {
  45.   BPTR lock;
  46.   static struct FileInfoBlock fib;
  47.   /*     ^^ must be longword aligned - vbcc guarantees that */
  48.  
  49.   if (lock = Lock(name,ACCESS_READ)) {
  50.     if (Examine(lock,&fib)) {
  51.       uint16 m = 0;
  52.       uint32 p;
  53.  
  54.       obj->time = UNIXOFFSET+(uint32)(fib.fib_Date.ds_Days*(60*60*24) +
  55.                                       fib.fib_Date.ds_Minute*60 +
  56.                                       fib.fib_Date.ds_Tick/TICKS_PER_SECOND);
  57.       obj->uid = fib.fib_OwnerUID;
  58.       obj->gid = fib.fib_OwnerGID;
  59.       p = fib.fib_Protection;
  60.       if (!(p & FIBF_READ))  m |= 0400;
  61.       if (!(p & FIBF_WRITE))  m |= 0200;
  62.       if (!(p & FIBF_EXECUTE))  m |= 0100;
  63.       if (p & FIBF_GRP_READ)  m |= 0040;
  64.       if (p & FIBF_GRP_WRITE)  m |= 0020;
  65.       if (p & FIBF_GRP_EXECUTE)  m |= 0010;
  66.       if (p & FIBF_OTR_READ)  m |= 0004;
  67.       if (p & FIBF_OTR_WRITE)  m |= 0002;
  68.       if (p & FIBF_OTR_EXECUTE)  m |= 0001;
  69.       obj->mode = m;
  70.     }
  71.     UnLock(lock);
  72.   }
  73. }
  74.  
  75.  
  76. char *filepart(char *path)
  77. /* Amiga version */
  78. {
  79.   return ((char *)FilePart((STRPTR)path));
  80. }
  81.  
  82. #else
  83.  
  84. void getfstat(struct ArObject *obj,char *name)
  85. /* Unix version */
  86. {
  87.   struct stat sb;
  88.  
  89.   if (!stat(name,&sb)) {
  90.     obj->time = (uint32)sb.st_mtime;
  91.     obj->uid = (uint16)sb.st_uid;
  92.     obj->gid = (uint16)sb.st_gid;
  93.     obj->mode = (uint16)sb.st_mode;
  94.   }
  95. }
  96.  
  97.  
  98. char *filepart(char *path)
  99. /* Unix version */
  100. {
  101.   char *ind;
  102.  
  103.   return ((ind = strrchr(path, '/')) ? ind + 1 : path);
  104. }
  105.  
  106. #endif
  107.